/* your js go here */
$(function () {


    $("#avatar").click(function () {
        console.log("你点击了头像");
        var url = $("#path").val();
        var userId = $("#userId").val();
        window.location.href = url + '/user/userLook?userId=' + userId;
    });

    $("#lookImg").click(function () {
       $("#picFile").click();
    });

    //file表单选中文件时,让file表单的val展示到showname这个展示框
    $('#picFile').change(function () {

        console.log("我选择了一张图片");
        var f = document.getElementById("picFile").files[0];
        var path = $("#path").val();
        var url = path + "/user/updateImg";
        var data = new FormData();
        data.append("f1",f);


        //下一步，使用ajax
        $.ajax({
            type:"post",
            url:url,
            contentType:false,
            processData:false,
            data:data,
            success:function (resp) {
                if(null != resp){
                    $("#lookImg").attr("src",resp);
                    $("#sideImg").attr("src",resp);
                }
            },
            error:function () {

            }

        })
    });

    //用户列表，查看详情，通过class名字userDetail来找
    $(".userDetail").click(function () {
        console.log("你点击了用户详情");
        var url = $("#path").val();
        var userId = $(this).attr("data-id");
        window.location.href = url + '/user/userDetail?userId=' + userId;
    });

    //发布会议跳转链接
    $("#addMeet").click(function () {
        var path = $("#path").val();
        window.location.href = path + '/meeting/addMeeting';
    });

    //添加文章跳转链接
    $("#addArt").click(function () {
        var path = $("#path").val();
        window.location.href = path + '/article/addArticle';
    });


    $(".myList>ul>li").on("click",function () {
        if($(this).find("div").attr('class')=='list-group myGroup isHidden'){
            $(this).find("div").removeClass("isHidden")
        }else{
            $(this).find("div").addClass("isHidden")
        }
    });

    $(".table").find("input[type='checkbox']").on("click",function () {
        //列表用户id
        var userId = $(this).attr("data-id");
        //用户id
        var uid = $("#id").val();
        if (uid === userId) {
            layer.msg("不能关注自己");
            $(this).prop("checked",false);
            return;
        }
        var url = $("#path").val();
        $.ajax({
            url: url + "/user/focus",
            type:"post",
            data:{uId:userId},
            success:function (data) {
                if (data === "0"){
                    layer.msg("取关成功");
                } else {
                    layer.msg("关注成功");
                }
            }
        });
    })
});

